<?php

namespace app\admin\model\business;

use app\admin\model\basic\Assets;
use think\Model;
use traits\model\SoftDelete;

class AssetsLog extends Model
{
    use SoftDelete;

    protected $name = 'assets_log';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    /**
     * Notes: 增加账户日志
     * User: AerYYY
     * Date: 2/5/24 11:25 AM
     * @param $parmas
     * @return bool
     */
    public function createLog($params): bool
    {
        $this->save([
            'staff_id' => $params['staff_id'],
            'assets_id' => $params['assets_id'],
            'status' => $params['status'],
            'order_no' => $params['order_no'],
            'date' => $params['date'],
            'be' => $params['be'],
            'price' => $params['price'],
            'admin_id' => $params['admin_id'] ?? 0 ,
            'balance' => Assets::where('id', $params['assets_id'])->value('balance')
        ]);

        return true;
    }
}